// pages/user/edit/index.js
const App=getApp()

Page({
  data:{
    info:[],
    id:0
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
   var id=options.id
    this.setData({
      id:id
    })
    this.getAddRessInfo(id)
  },
  formReset:function(){
    wx.navigateBack({
      delta: 1, // 回退前 delta(默认为1) 页面
    })
  },
  getAddRessInfo:function(id){
    var that=this
    App.HttpService.getUserAddRessInfo({
      id:id
    }).then(data=>{
      if(data.meat.code==0){
        that.setData({
            info:data.data
        })
      }
    })
  },
  formSubmitSave:function(e){
   var data=e.detail.value
   var id=this.data.id
    wx.showToast({
      title: '修改中',
      icon: 'loading',
      duration: 100000
    })

   App.HttpService.editUserRess({
     id:id,
      name:data.name,
      phone:data.phone,
      address:data.address,
      cityID:data.cityID
   }).then(data=>{
      if(data.meat.code==0){
        setTimeout(function(){
          wx.hideToast()
          wx.navigateTo({
            url: '../address/index',
          })
        },2000)
      }
   })
  }
})